package xyz.xtt.exchange.controller;

import java.util.Objects;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import xyz.xtt.common.response.ApiResult;
import xyz.xtt.exchange.entity.TblMerchantInfo;
import xyz.xtt.exchange.mapper.TblMerchantInfoMapper;
import xyz.xtt.exchange.service.ITblMerchantInfoService;

/**
 * @author wangqi
 */
@Slf4j
@RestController
@RequestMapping("/api/exchange/merchant")
public class MerchantInfoController {
	@Autowired
	TblMerchantInfoMapper tblMerchantInfoMapper;

	@Autowired
	ITblMerchantInfoService iTblMerchantInfoService;

	@Operation(summary = "添加商户")
	@PostMapping("/create")
	public ApiResult<String> createMerchant(@RequestHeader("uid") Long uid, int shopId) {
		tblMerchantInfoMapper.insertMerchantInfo(IdUtil.getSnowflakeNextId(), shopId, DateUtil.currentSeconds(), uid);
		return ApiResult.ok();
	}

	@Operation(summary = "商户审核查询")
	@GetMapping("/get_mch_shop_id")
	public ApiResult<String> getMchShopId(@RequestHeader("uid") Long uid) {
		TblMerchantInfo mchShop = iTblMerchantInfoService.getMchShop(uid);
		return ApiResult.ok(Objects.isNull(mchShop) ? "" : mchShop.getShopId().toString());
	}

	/**
	 * 通过用户Id获取存在商家信息如果存在就是商家，如果为空则就是普通用户返回为false，商家是true
	 * 
	 * @param uid
	 * @return
	 */
	@GetMapping("/judgeMerchantPer")
	@Operation(summary = "查询是否为商户还是个人", description = "查询是否为商户还是个人")
	public ApiResult<Boolean> judgeMerchantPer(@RequestHeader("uid") String uid) {
		Boolean judgeMerchantPer = iTblMerchantInfoService.judgeMerchantPer(uid);
		return ApiResult.ok(judgeMerchantPer);
	}
	
}
